<?php
require("../inc/common.inc.php");
$web_title="会员注册";
@header('Content-Type:text/html;charset= utf-8');
if ($actions=="save"){
	$devicenum=intval($devicenum);
	$uppassword="";

	if(trim($mobile)==""){
		$fun->popmassage("手机号码不能为空！","","popback");
		exit();
	}
	if (trim($mobile)!=""){
		if(!eregi("^1[0-9]{10}$",$mobile))
		{
			$fun->popmassage("手机号码格式不正确","","popback");
			exit();
		}
	}
	$havedl=$db->getinfo("select id from mx_app_user  WHERE username='$mobile'");
	if(is_array($havedl)){
		$fun->popmassage("手机号已经存在！","","popback");
		exit();
	}
	if(trim($password)==""){
		$fun->popmassage("登录密码不能为空！","","popback");
		exit();
	}
	if(trim($repassword)==""){
		$fun->popmassage("密码确认不能为空！","","popback");
		exit();
	}
	if ($password!=$repassword){
		$fun->popmassage("两次输入密码不一致，请重新输入！","","popback");
		exit();
	}
	$isok=intval($isok);
	$password=md5($password);
	$ip=$_SERVER['REMOTE_ADDR'];
	$date=date("Y-m-d H:i:s");
	$files=array(
			"vppuserid"		=>$vpp_user_info['id'],
			"username"             =>$mobile,
			"realname"         =>$realname,
			"password"         =>$password,
			"mobile"            =>$mobile,
			"regdate" => $date,
			"isok" => 1,
			"logintimes" => time(),
			"lastloginiP"	=> $ip,
			"lastlogintime" => $date
	);
	$db->exe_insert("mx_app_user",$files);
	//注册成功，写入COOKIE并直接登录
	$userObj=$db->excu("SELECT * FROM mx_app_user WHERE username='$mobile' and password='$password' ");
	$info=$db->fetch_array($userObj);
	if($info){
		$time = time()+3600*24*30;
		setcookie('userid',$info["id"],$time,'/');
		setcookie('username',$info["username"],$time,'/');
		setcookie('password',$info["password"],$time,'/');
		setcookie('realname',$info["realname"]?$info["realname"]:$info["username"],$time,'/');
		setcookie('LastLoginTime',$info["lastlogintime"],$time,'/');
		//注册成功，积分增加
		$integral = 40;
		addIntegral($integral, $info["id"], "注册会员");
		$targetuserid = $_COOKIE['share_targetuserid'];
		if($targetuserid){
			$newIntegral = $integral/2;
			giveIntegral($targetuserid,$newIntegral,"分享注册",2);
		}
		echo "<script>alert('注册成功，请牢记您的用户名和密码！');location.href='/user/index.php';</script>";
	}
	exit();
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta content="width=device-width,user-scalable=no,initial-scale=1,maximum-scale=1" name="viewport">
<title><?php echo $web_title;?></title>
<meta content="no-cache,must-revalidate" http-equiv="Cache-Control">
<meta content="no-cache" http-equiv="pragma">
<meta content="0" http-equiv="expires">
<meta content="telephone=no, address=no" name="format-detection">
<meta content="width=device-width, initial-scale=1.0" name="viewport">
<meta name="apple-mobile-web-app-capable" content="yes" /> <!-- apple devices fullscreen -->
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
</head>
<body>
<?php require("../w_head.php")?>
<div class="zuce_t">会员注册</div>


<div class="zuce_c">
<form name="form1" id="form1" method="post" action="regist.php?actions=save"  onsubmit="return dianji();">
 <ul>
  <li>真实姓名：</li>
  <li> <input type="text" name="realname" size="13" class="input1" /></li>
  <li>手机号：</li>
  <li> <input type="text" name="mobile" size="13" class="input1" /></li>
  <li>密 &nbsp;&nbsp;码：</li>
  <li><input type="password" name="password" size="20" class="input1"/></li>
  <li>确认密码：</li>
  <li><input type="password" name="repassword" size="20" class="input1"></li>
 </ul>
  
 <dt style="margin-top:20px;"><a href="javascript:void(0)" onclick="$('#form1').submit();" class="submit" id="showcard1" style="color:#ffffff">注册</a></dt>
  </form>
 <p> 已有账号?<a href="Login.php">马上登录</a>  </p>
</div>
<script language="javascript">
 function dianji(){
  
   /* if(document.all.oldpass.value==""){
	  alert("请输入旧密码！");
	  document.all.oldpass.focus();
	  return false;
	}else{
	 if(document.all.oldpass.value.length<6){
	    alert("旧密码不能少于6个字符!"); 
	    document.all.oldpass.focus();
		return false;
	 }
	}
	if(document.all.password.value==""){
	  alert("请输入新密码！");
	  document.all.password.focus();
	  return false;
	}else{*/

	if(document.all.realname.value==""){
		alert("请输入真实姓名！");
		document.all.realname.focus();
		return false;
	}
	if(document.all.mobile.value.length<11){
	    alert("手机号不能少于11个字符!请输入手机号！"); 
	    document.all.mobile.focus();
		return false;
	 }
	 
	 if(document.all.password.value.length<6){
	    alert("密码不能少于6个字符!请输入密码！"); 
	    document.all.password.focus();
		return false;
	 }else{
	  if(document.all.repassword.value!=document.all.password.value){
	     alert("两次输入的密码不同！");
	     document.all.repassword.focus();
		 return false;
	  }
	}
	return true;
}
</script>
<?php require("../w_foot.php")?>